<template>
  <el-card>
    <el-form :model="tableData" label-width="120px" :rules="rules">
      <el-form-item label="分类名称">
        <el-input v-model="tableData.name" />
      </el-form-item>
      <el-form-item label="上级分类">
        <el-select v-model="tableData.classify" placeholder="无上级分类">
          <el-option label="无上级分类" value="shanghai" />
          <el-option label="123" value="shanghai" />
          <el-option label="234" value="shanghai" />
        </el-select>
      </el-form-item>
      <el-form-item label="数量单位">
        <el-input v-model="tableData.dataunit" />
      </el-form-item>
      <el-form-item label="排序">
        <el-input v-model="tableData.sort" />
      </el-form-item>
      <el-form-item label="是否显示">
        <el-radio-group v-model="tableData.isshow">
          <el-radio :label="1" size="large">是</el-radio>
          <el-radio :label="0" size="large">否</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="是否显示在导航栏">
        <el-radio-group v-model="tableData.Navigation">
          <el-radio :label="1" size="large">是</el-radio>
          <el-radio :label="0" size="large">否</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="分类图表">
        <el-button class="mt-2" type="primary">点击上传</el-button>
      </el-form-item>
      <el-form-item label="筛选属性">
        <el-select v-model="tableData.select" placeholder="请选择">
          <el-option label="Zone one" value="shanghai" />
          <el-option label="Zone two" value="beijing" />
        </el-select>
        <el-button class="mt-2">删除</el-button>
      </el-form-item>
      <el-form-item>
        <el-button type="primary">增加</el-button>
      </el-form-item>
      <el-form-item label="关键词">
        <el-input v-model="tableData.keyword" />
      </el-form-item>
      <el-form-item label="分类描述">
        <el-input v-model="tableData.context" type="textarea" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="addListData(tableData.name)"
          >提交</el-button
        >
        <el-button @click="clearData">重置</el-button>
      </el-form-item>
    </el-form>
  </el-card>
</template>

<script setup lang="ts">
import { ref, reactive, toRefs } from "vue";
import type { FormRules } from "element-plus";
import { useRoute, useRouter } from "vue-router";
import * as api from "../../request/api";

const router = useRouter();
// 定义添加的数据
let tableData = reactive({
  name: "123",
  classify: "",
  dataunit: "",
  sort: "",
  isshow: "",
  Navigation: "",
  select: "",
  keyword: "",
  context: "",
});
console.log(tableData.name);
console.log(tableData);
// 添加事件
let addListData = (name: string) => {
  console.log("添加成功");
  api.productCate.adminproductCate({
    parentId: name,
  });
};
// 重置
let clearData = () => {
  tableData = reactive({
    name: "123",
    classify: "",
    dataunit: "",
    sort: "",
    isshow: "",
    Navigation: "",
    select: "",
    keyword: "",
    context: "",
  });
};

const rules = reactive<FormRules>({
  name: [
    { required: true, message: "Please input Activity name", trigger: "blur" },
    { min: 3, max: 5, message: "Length should be 3 to 5", trigger: "blur" },
  ],
});
</script>

<style lang="scss" scoped>
.el-card {
  margin: 0 auto;
  width: 792px;
  box-sizing: border-box;
  padding: 35px 35px 15px;
}
</style>
